package com.codedef.diary.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class DateUtil {

    // 将yyyy-MM-ddTHH:mm:ss+mm:ss格式日期转成Date类型
    public static Date dateConverter2(String dateStr) {
        Date date = null;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.000+'mm:ss", Locale.CHINA);
        try {
            date = simpleDateFormat.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static Date dateConverter(String dateStr) {
        Date date = null;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss", Locale.CHINA);
        try {
            date = simpleDateFormat.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static String outFormat(Date date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss", Locale.CHINA);
        return simpleDateFormat.format(date);
    }

    public static String outFormatNYR(Date date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日' 'HH:mm:ss", Locale.CHINA);
        return simpleDateFormat.format(date);
    }

    public static String getMonthNoZero(Date date) {
        String moth = outFormat(date).substring(5, 7);
        return moth.charAt(0) == '0' ? moth.substring(1, 2) : moth;
    }

    public static String getDayhNoZero(Date date) {
        String day = outFormat(date).substring(8, 10);
        return day.charAt(0) == '0' ? day.substring(1, 2) : day;
    }

    public static String getWeek(Date date) {
        SimpleDateFormat dateFm = new SimpleDateFormat("EEEE");
        return '周' + dateFm.format(date).substring(2, 3);
    }

}
